#pragma once

#include "Hash.h"

namespace Myunordered_set
{
	template<class K>
	class unordered_set
	{
		struct setkeyoft
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

	public:
		typedef typename Hash_bucket::HashBucket<K, K, setkeyoft>::iterator iterator;

		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		//bool insert(const K& key)
		//{
		//	return _ht.Insert(key).second;
		//}

		pair<iterator, bool> insert(const K& valye)
		{
			return _ht.Insert(valye);
		}

		iterator erase(iterator position)
		{
			return _ht.Erase(position);
		}

		iterator find(const K& key) 
		{
			return iterator(_ht.Find(key),this); 
		}

		size_t bucket_count() 
		{
			return _ht.BucketCount(); 
		}



	private:
		Hash_bucket::HashBucket<K, K, setkeyoft> _ht;
	};

	void test_set1()
	{
		unordered_set<int> us;
		us.insert(3);
		us.insert(1);
		us.insert(5);
		us.insert(15);
		us.insert(45);
		us.insert(7);
		us.insert(6);
		us.insert(433);
		us.insert(2);
		us.insert(22);
		us.insert(23);

		unordered_set<int>::iterator it = us.begin();
		while (it != us.end())
		{
			//*it += 100;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : us)
		{
			cout << e << " ";
		}
		cout << endl;
	}
}
